<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN">
<html xmlns="http://www.w3.org/1999/xhtml" style="overflow-x: hidden; overflow-y: auto;">
<head>
	<title>澳门投注信息</title>
	<style type="text/css">
	<!--
  BODY {
    font-family:    Arial, Verdana, Helvetica, sans-serif;
    font-size:      13px;
    background:     #d9d9d9;
    color:          black;
    margin:         0;
    padding:        0;
    border:         0;
  }
  TABLE { 
    border-spacing:  0;
    border-collapse: collapse;
    padding:         0;
    margin:          0;
    border:          0;
  }
  TD { 
    vertical-align:  middle;
    font-size:       13px;
    border-spacing:  0;
    border-collapse: collapse;
    border:          0;
    padding:         2px;
    margin:          0;
  }
  TR.header {
    background:     #007B32;
    color:          white;
  }
  TD.btop {
    border-top: 1px solid white;
  }
  TD.bbot {
    border-bottom: 1px solid white;
  }
  A.info {
    color: red;
    text-decoration: none;
  }
  A.info:visited {
    color:red;
  }
  *.bbot2 {
    border-bottom: 1px solid white;
  }
  INPUT.blocked {
    background-color: gray;
  }
	-->
	</style>

	<script type="text/JavaScript" language="JavaScript">
	<!--

top.fm_betslip = self;
var loaded = undefined;

if (!Array.indexOf) {
	Array.prototype.indexOf = function(obj) {
		for (var i=0; i < this.length; i++){
			if (this[i]==obj) {
				return i;
			}
		}
		return -1;
	};
}

if (!Array.copy) {
	Array.prototype.copy = function() {
		var copy = new Array();
		for (var i = 0; i < this.length; i++) {
			copy[i] = this[i];
		}
		return copy;
	};
}

if (!Array.slice) {
	Array.prototype.slice = function(start,end) {
		var temp;
		if (end == null || end == '') {
			end = this.length;
		} else if (end < 0) {
			end = this.length + end;
		}
		if (start < 0) {
			start = this.length + start;
		}
		if (end < start) {
			temp = end;
			end = start;
			start = temp;
		}
		var newArray = new Array();
		for (var i=0; i < end - start; i++) {
			newArray[i] = this[start+i];
		}
		return newArray;
	};
}

if (!Array.splice) {
	Array.prototype.splice = function(start, deleteCount) {
		if (deleteCount == null || deleteCount == '') {
			deleteCount = this.length - start;
		}
     
		var tempArray = this.copy();
     
		for (var i = start; i < start + arguments.length - 2; i++) {
			this[i] = arguments[i - start + 2];
		}
     
		for (var i = start + arguments.length - 2; i < this.length - deleteCount + arguments.length - 2; i++) {
			this[i] = tempArray[i + deleteCount - arguments.length + 2];
		}
		this.length = this.length - deleteCount + (arguments.length - 2);
		return tempArray.slice(start, start + deleteCount);
	};
}

var seln_ids = new Array();
var seln_info = new Object();
var mul_seln_ids = new Array();
var bet_types = new Array();
var bet_type_info = new Object();
var pptimer = null;
var p_stakes = new Array();
var p_payouts = new Array();
var p_max_pay_over = new Array();
var max_payout_over = 0;

document.onkeypress = function (e) {
	e = (e)?e:window.event;
	keyCode=(e.keyCode)?e.keyCode:e.which;
	if (keyCode == 13) {
		e.returnValue = false;
		e.cancel = true;
		submit_bets();
	}
}
if (document.layers) {
	document.captureEvents(Event.KEYPRESS);
}

function clear_selns() {
	var fm = document.forms.betslip_form;
	fm.action2.value    = "clear";
	fm.submit();
}

function remove_seln(oc_id) {
	var fm = document.forms.betslip_form;
	fm.action2.value    = "remove";
	fm.oc_id.value      = oc_id;
	fm.submit();
}

function banker_changed(oc_id) {
	var fm = document.forms.betslip_form;
	fm.action2.value    = "banker_changed";
	fm.oc_id.value      = oc_id;
	fm.submit();
}

function submit_bets() {
	var fm = document.forms.betslip_form;
	var settings = '';
	var w = 720;
	var h = 510;	
	var x = (screen.width - w) / 2;
	var y  = (screen.height - h) / 2;	
	settings += 'width=' + w + ',height=' + h;
	settings += ',top=' + y + ',left=' + x;
	settings += ',scrollbars=yes,resizable=no'; 
	window.open('','slot_bs_pop',settings);
	fm.max_payout_over.value = max_payout_over;
	fm.target = "slot_bs_pop";
	fm.action2.value = "submit";
	fm.submit();
	fm.target = "_self";
}

var stk_whole_number = 1;
function stake_changed(obj) {
	if (!stk_whole_number) {
		var stk = obj.value;
		var dp_pos = stk.indexOf(".");
		if (dp_pos >= 0) {
			obj.value = stk.substring(0,dp_pos+3);
		}
	}
	clearTimeout(pptimer);
	pptimer = setTimeout("update_totals();",500);
}

function validate_stake(obj, e) {	
	var key,is_ctrl,key_char;
	if (window.event) {
		key = e.keyCode;
		is_ctrl = window.event.ctrlKey;
	} else if (e.which) {
		key = e.which;
		is_ctrl = e.ctrlKey;
	}
	if (isNaN(key)) {
		return true;
	}
	key_char = String.fromCharCode(key);	
	if (key == 8 || is_ctrl) {
		return true;
	}
	var is_first_d;
	if (stk_whole_number) {
		if (obj.value == "" && key_char == "0") {
			return false;
		}
		is_first_d = false;
	} else {
		if (key_char != "." && obj.value == "0") {
			return false;
		}
		is_first_d = key_char == "." && obj.value.indexOf(".") == -1 && obj.value != "";
	}
	var reg = /\d/;
	return is_first_d || reg.test(key_char);	
}

function gen_perms(m,xs) {
	var x, perms, sub_perms, sub_perm, i, j, l;
	if (m < 1) {
		return new Array();
	} else if (m == 1) {
		perms = new Array();
		l = xs.length;
		for (i = 0; i < l; i++) {
			sub_perm = new Array();
			sub_perm.push(xs[i]);
			perms.push(sub_perm);
		}
		return perms;
	} else {
		perms = new Array();
		m--;
		for (i = 0; i < xs.length - m; i++) {
			x = xs[i];
			sub_perms = gen_perms(m, xs.slice(i+1));
			l = sub_perms.length;
			for (j = 0; j < l; j++) {
				sub_perm = sub_perms[j];
				sub_perm.unshift(x);
				perms.push(sub_perm);
			}
		}
		return perms;
	}
}

function gen_lines(perm_size, non_bankers, bankers) {
	var lines = gen_perms(perm_size - bankers.length, non_bankers);
	var l = lines.length;
	for (var i = 0; i < l; i++) {
		lines[i] = bankers.concat(lines[i]);
	}
	return lines;
}

function multiple_payout(bet_type, stake) {
	var i, j;
	var line, seln_id;
	var payout;
	var total_payout = 0;
	var bt = bet_type_info[bet_type];
	var is_complex = bt.is_complex;
	var payout_calc_data = bt.payout_calc_data;
	var num, den;
	p_max_pay_over[bet_type] = 0;
	if (payout_calc_data.length == 0) {		
		return "unknown";
	}
	
	if (is_complex) {
		var lines = gen_lines(payout_calc_data[0],payout_calc_data[1],payout_calc_data[2]);
	} else {
		var lines = payout_calc_data;
	}

	var l = lines.length;
	var ll;

	for (i = 0; i < l; i++) {
		line = lines[i];
		num = 1;
		den = 1;
		ll = line.length;
		for (j = 0; j < ll; j++) {
			seln_id = line[j];
			if (!is_complex) {
				seln_id = mul_seln_ids[seln_id - 1];
			}
			num *= seln_info[seln_id].lp_num + seln_info[seln_id].lp_den;
			den *= seln_info[seln_id].lp_den;
		}
		payout = stake * (num / den);
		if (payout > bt.max_payout * 100) {
			payout = bt.max_payout * 100;
			p_max_pay_over[bet_type] = 1;
		}
		total_payout += payout;
	}
	return total_payout;
}

var combi_mkt_sorts = {"21,WH" : {"OE" : 1, "HL" : 1, "1H" : 1, "2H" : 1}, "21,ML" : {"OE" : 1, "HL" : 1, "1H" : 1, "2H" : 1}, "21,1W" : {"OE" : 1, "HL" : 1, "1H" : 1, "2H" : 1}, "21,2W" : {"OE" : 1, "HL" : 1, "1H" : 1, "2H" : 1}, "21,HL" : {"ML" : 1, "OE" : 1, "WH" : 1, "1W" : 1, "2W" : 1}, "21,1H" : {"ML" : 1, "OE" : 1, "WH" : 1, "1W" : 1, "2W" : 1}, "21,2H" : {"ML" : 1, "OE" : 1, "WH" : 1, "1W" : 1, "2W" : 1}, "21,OE" : {"ML" : 1, "WH" : 1, "1W" : 1, "2W" : 1, "HL" : 1, "1H" : 1, "2H" : 1}};

function singles_payout() {
	var i, id, j, inp, mkt_sort, mkt_sorts;
	var total_payout = 0;
	var stake, num_lines, payout;	
	var uncombinables = new Object();
	for (i = 0; i < seln_ids.length; i++) {
		id = seln_ids[i];
		inp = document.getElementById("stake_" + id);
		if (inp && inp.value && !isNaN(inp.value) && inp.value > 0) {		
			if (!uncombinables[seln_info[id].ev_id]) {
				uncombinables[seln_info[id].ev_id] = new Array();
				uncombinables[seln_info[id].ev_id].push(seln_info[id].mkt_sort);						
			} else {
				var mkt_sort = seln_info[id].mkt_sort;
				mkt_sorts = uncombinables[seln_info[id].ev_id];
				var key = seln_info[id].ev_class_id + "," + mkt_sort;
				var combinable = combi_mkt_sorts[key];
				if (!combinable) {
					return "unknown";
				}
				for (j = 0; j < mkt_sorts.length; j++) {
					if (!combinable[mkt_sorts[j]]) {
						return "unknown"
					}
					
				}
				uncombinables[seln_info[id].ev_id].push(seln_info[id].mkt_sort);		
			}
			stake = 100 * inp.value;
			payout = stake + stake * seln_info[id].lp_num / seln_info[id].lp_den;
			if (payout > seln_info[id].max_payout * 100) {
				payout = seln_info[id].max_payout * 100;
				max_payout_over = 1;
			}
			total_payout += payout;
		}
	}
	return total_payout;
}


function possible_payout() {
	var i, id, inp;
	var total_payout = 0;	
	var stake, num_lines, payout;	
	var payout = singles_payout();
	if (isNaN(payout)) {
		return "unknown";
	}
	total_payout += payout;
	for (i = 0; i < bet_types.length; i++) {
		id = bet_types[i];
		inp = document.getElementById("stake_" + id);
		if (inp && inp.value && !isNaN(inp.value) && inp.value > 0) {
			stake = 100 * inp.value;
			if (p_stakes[id] != null && p_stakes[id] == stake) {
				payout = p_payouts[id];
			} else {
				payout = multiple_payout(id, stake);
				p_stakes[id] = stake;
				p_payouts[id] = payout;
			}
			if (p_max_pay_over[id] == 1) {
				max_payout_over = 1;
			}
			if (isNaN(payout)) {
				return "unknown";
			}
			total_payout += payout;
		} else {
			p_stakes[id] = null;
			p_payouts[id] = 0;
			p_max_pay_over[id] = 0;
		}
	}
	return Math.floor(total_payout) / 100;

}

function round_to_2_dp(num) {
	num = Math.round(num*Math.pow(10,2))/Math.pow(10,2);
	var str = "" + num;
	var l = str.length;
	var x = str.indexOf('.');

	if (x == -1) {
		return str + ".00";
	}

	if (x == l-2) {
		return str + "0";
	}

	return str;
}

function update_totals() {
	max_payout_over = 0;
	clearTimeout(pptimer);
	if ( document.getElementById("total_lines_span") == null ) {
		return;
	}	
	var i, id, inp;
	var stake, num_lines;	
	var total_lines = 0;
	var total_stake = 0;	
	var ids = seln_ids.concat(bet_types);
	for (i = 0; i < ids.length; i++) {
		id = ids[i];
		inp = document.getElementById("stake_" + id);
		if (inp && inp.value && !isNaN(inp.value) && inp.value > 0) {
			stake = inp.value;
			inp = document.getElementById("num_lines_" + id);
			if (inp && inp.value && !isNaN(inp.value) && inp.value > 0) {
				num_lines = inp.value;
			} else {
				num_lines = 1;
			}
			total_lines += num_lines * 1;
			total_stake += stake * 100 * num_lines;
		}
	}

	document.getElementById("total_lines_span").innerHTML = total_lines;
	document.getElementById("total_stake_span").innerHTML = round_to_2_dp(total_stake / 100);
	var payout = possible_payout();
	if (payout == "unknown") {
		document.getElementById("possible_payout_row").style.display = "none";
		document.getElementById("possible_payout_span").innerHTML = "";
	} else {
		document.getElementById("possible_payout_row").style.display = "";
		document.getElementById("possible_payout_span").innerHTML = round_to_2_dp(payout);
	}
	
}

function clear_stakes() {
	var ids = seln_ids.concat(bet_types);
	var inp;
	for (var i = 0; i < ids.length; i++) {
		id = ids[i];
		inp = document.getElementById("stake_" + id);
		if (inp) {
			inp.value = "";
		}
	}
	update_totals();
}

function init() {
	loaded = true;	
	update_totals();
}
	//-->
	</script>

</head>
<body onload="init()">
  <form onsubmit="return false" name="betslip_form" action="/cust" method="post">
  <table width="100%">  
    <colgroup>       
      <col width="20"/>
      <col width="2"/>
      <col width="105"/>      
      <col/>
      <col/>
    </colgroup>
	<tbody>
    <tr class="header">		
      <td colspan="5" class="bbot btop">
        胆<span style="position: absolute; left: 120px;">单式</span>
      </td>		
    </tr>
	<script type="text/JavaScript" language="JavaScript">
	<!--
		seln_ids.push('4586328');
		seln_info['4586328'] = {lp_num : 1100, lp_den : 1000, max_payout : 500000, ev_class_id : 18, ev_id : 87257, mkt_sort : 'AH'};
	// -->
	</script>
	<tr>
    <td align="center">	
      <input type="checkbox" onclick="banker_changed('4592112')"/>	
		</td>
		<td>1.</td>		
		<td align="left" colspan="3">墨西哥 對 美国</td>
	</tr>
	<tr>
		<td> </td>
		<td> </td>
		<td align="left" colspan="3">亚洲让球盘 - 走地盘</td>
	</tr>		
	<tr>		
		<td> </td>		
		<td> </td>
		<td align="left" colspan="3">墨西哥 0 / -0.5</td>
	</tr>		
	<tr>
		<td> </td>
		<td> </td>
		<td align="left" colspan="3">墨西哥 @ 2.1</td>
	</tr>	
	<tr>
		<td class="bbot2"> </td>
		<td class="bbot2"> </td>		
		<td class="bbot2"> </td>		
		<td nowrap="" align="left" class="bbot2">
			<img title="最低投注限额: $10.00
最高投注限额: $10,000.00
最高派彩限额: $500,000.00" src="info.gif" alt="" style="cursor: pointer;"/>			 
			$
		</td>
		<td nowrap="" class="bbot2">		
			<input type="text" onkeypress="return validate_stake(this,event)" onkeyup="stake_changed(this)" value="" maxlength="12" size="6" id="stake_4586328" name="stake_4586328"/>		
			<img onclick="remove_seln('4586328')" alt="删除" src="remove.gif" style="cursor: pointer;"/>
    </td>
	</tr>
	<tr class="header">
		<td align="right" colspan="4" class="btop">注数:</td>
		<td align="left" class="btop"> <span id="total_lines_span">0</span></td>
	</tr>	
	<tr class="header">
		<td align="right" colspan="4">投注金额:</td>
		<td align="left"> <span id="total_stake_span">0.00</span></td>
	</tr>	
	<tr class="header" id="possible_payout_row">
		<td align="right" colspan="4" class="bbot">最高可赢派彩:</td>
		<td align="left" class="bbot"> <span id="possible_payout_span">0.00</span></td>
	</tr>
	<tr>		
		<td align="right" colspan="4">
			<input type="button" onclick="submit_bets()" value="投注"/>
			<input type="button" onclick="clear_selns()" value="清除"/>
		</td>
		<td> </td>		
	</tr>
</tbody>
</table>
</form>
</body>
</html>